package com.raycloud.robot.transfor;

import java.util.concurrent.TimeUnit;
import com.google.common.cache.CacheBuilder;
import com.hankcs.hanlp.HanLP;
import org.apache.commons.lang3.StringUtils;
import com.google.common.cache.Cache;

public class HkToSimpleUtils{
    private static Cache<String,String> cache;
    public static String toSimple(final String str){
        return toSimple(str,false);
    }
    public static String toSimple(final String str,final boolean isCache){
        if(StringUtils.isBlank(str)){
            return "";
        }
        String message=HkToSimpleUtils.cache.getIfPresent(str);
        if(StringUtils.isNotBlank(message)){
            return message;
        }
        message=HanLP.hk2s(str);
        if(isCache){
            HkToSimpleUtils.cache.put(str,message);
        }
        return message;
    }
    static{
        HkToSimpleUtils.cache=CacheBuilder.newBuilder().expireAfterAccess(3L,TimeUnit.MINUTES).maximumSize(5000L).weakValues().build();
    }
}
